<template>
    <div>
        <div class="mui-numbox" data-numbox-min="1" :data-numbox-max="max">
            <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
            <input @change="countChanged" ref="num" class="mui-input-numbox" type="number" value="1">
            <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
        </div>
    </div>
</template>

<script>
    import mui from '../../lib/mui/js/mui.min.js'
    export default {
        name: "goodsInfo_number",
        props:['max'],
        mounted(){
            //初始化数字框的控件
            mui('.mui-numbox').numbox();
            // console.log(this.max);
        },
        watch:{
            //监听数字的改变:只要值改变，就立马设置最大值
            'max':function (newVal) {
                // console.log(newVal)
                mui('.mui-numbox').numbox().setOption('max',newVal);
            }
        },
        methods:{
            countChanged(){
                //给元素添加ref属性，值自己定义就能得到$refs对象，可以通过这个对象获取对应节点的一系列值
                // console.log(this.$refs.num.value)
                this.$emit('getCount',parseInt(this.$refs.num.value));
            }
        }
    }
</script>

<style scoped>

</style>